package org.file_service.config;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

@Configuration
public class HdfsConfig {

    @Value("${hdfs.master.uri}")
    private String hdfsMasterUri;

    @Value("${hdfs.user}")
    private String userName;

    @Bean
    public FileSystem init() throws URISyntaxException, IOException, InterruptedException {
        //创建一个配置文件
        org.apache.hadoop.conf.Configuration configuration = new org.apache.hadoop.conf.Configuration();
        configuration.set("dfs.replication","2");
        //1获取到客户端对象
        return FileSystem.get(new URI(hdfsMasterUri), configuration, userName);
    }

}
